<!--- Start - Check PRF if Routed --->
<CFSET sMessPostApproval = "">
<CFQUERY NAME="qryECINPRF" DATASOURCE="#client.company_dsn#">
	SELECT *
	FROM   ECINPRF
	WHERE  ROUTEID = '#GetRecord.ROUTEID#'
</CFQUERY>
<!--- End - Check PRF if Routed   --->
<!--- Start - IF - PRF Exist --->
<CFIF qryECINPRF.RecordCount>
	<CFSET platform = #qryECINPRF.PLATFORM#>
	<CFSET messageListEmailed = "">
	<CFSET messageCatch = "">
	<CFSET messageListNoEmail = "">
	
	<!--- Start - Get all Client/Customer with ACTIVE status --->
	<CFQUERY NAME="qryCMFCUSTOMER" DATASOURCE="#client.company_dsn#">
		SELECT CUSTOMERCODE, CUSTPLATFORMCODE, EMAIL1, EMAIL2, EMAIL3, CONTACT1, CONTACT2, CONTACT3
		FROM   CMFCUSTOMER
		where CUSTOMERSTATUS like 'ACTIVE'
		AND CUSTPLATFORMCODE IN (#getCodes(platform)#)
	</CFQUERY>
	<!--- End - Get all Client/Customer with ACTIVE status   --->
	
	<!--- Start - If - Active Customer Exist --->
	<CFIF qryCMFCUSTOMER.RecordCount>
		<!--- Start - Get Record of Mail Template --->
		<CFQUERY NAME="qryEGRGEMAILTEMPLATES" DATASOURCE="#client.global_dsn#">
			SELECT * 
			FROM EGRGEMAILTEMPLATES
			WHERE MAILCODE like '#qryECINPRF.MAILCODE#'
		</CFQUERY>
		<!--- End - Get Record of Mail Template   --->
		
		<!--- Start - If - Template Exist --->
		<CFIF qryEGRGEMAILTEMPLATES.RecordCount>
			<CFSET mailSubject = #qryEGRGEMAILTEMPLATES.SUBJECT#>
			<CFSET mailMessage = #qryEGRGEMAILTEMPLATES.MESSAGE#>
			<CFSET mailHeader  = #qryEGRGEMAILTEMPLATES.MAILHEADER#>
			<CFSET mailFooter  = #qryEGRGEMAILTEMPLATES.MAILFOOTER#>
			
			<!--- Start - Get Attachment File --->
			<CFQUERY NAME="qryECINFORMSATTACH" DATASOURCE="#client.company_dsn#">
				SELECT ATTACHFILECODE,DESCRIPTION 
				FROM ECINFORMSATTACH 
				WHERE ATTACHMENTCODE like '#qryECINPRF.ATTACHMENTCODE#'
			</CFQUERY>
			<!--- End - Get Attachment File   --->
			
			<!--- Start - Get Email and Name of Creator --->			
			<CFQUERY NAME="qryTESTER" DATASOURCE="#client.global_dsn#">
				SELECT A.LASTNAME + ', ' + A.FIRSTNAME AS FULLNAME, B.PROFILENAME AS EMAIL 
				FROM GMFPEOPLE A 
				INNER JOIN EGRGUSERMASTER B ON A.GUID = B.GUID
				WHERE B.USERID ='#qryECINPRF.ACTIONBY#'
			</CFQUERY>
			<!--- End - Get Email and Name of Creator   --->
			
			<CFIF qryTESTER.RecordCount>
				<CFIF qryTESTER.EMAIL NEQ "">
					<CFSET mailFrom = #qryTESTER.EMAIL#>
				<CFELSE>
					<CFSET mailFrom = #qryEGRGEMAILTEMPLATES.DEFAULTSENDER#>
				</CFIF>
				<CFIF qryTESTER.FULLNAME NEQ "">
					<CFSET testerName = "#qryTESTER.FULLNAME#">
				<CFELSE>
					<CFSET testerName = "Digital Infostructure">
				</CFIF>
			</CFIF>
			<CFIF qryECINFORMSATTACH.RecordCount>
				<!--- Start - Loop - Rename the File Attached --->
				<CFSET attachedFile = ArrayNew( 1 )>
				<CFSET ctr1 = 1>
				<CFLOOP QUERY = "qryECINFORMSATTACH">
					<CFSET filename  = qryECINFORMSATTACH.ATTACHFILECODE>
					<CFSET extension = listLast(qryECINFORMSATTACH.DESCRIPTION,".")>
					<CFSET shouldBeFilename = qryECINFORMSATTACH.DESCRIPTION>
					<CFSET attachedFile[ctr1] = renameFile("#client.attachment_path##filename#.#extension#","#client.attachment_path##shouldBeFilename#")>
					<CFSET ctr1 = ctr1 + 1>
				</CFLOOP>
				<!--- End - Loop - Rename the File Attached   --->
			</CFIF>
			<!--- Start - Loop - Customer --->
			<CFLOOP QUERY = "qryCMFCUSTOMER">
				<!--- Start - If - Email Exist --->
				<CFIF #qryCMFCUSTOMER.EMAIL1# NEQ "" OR  #qryCMFCUSTOMER.EMAIL2# NEQ "" OR  #qryCMFCUSTOMER.EMAIL3# NEQ "">
					<CFSET mailTo = #getEmail(qryCMFCUSTOMER)#>
					<CFSET contactName = #getContactName(qryCMFCUSTOMER)#>
					<CFTRY>
						<!--- Start - Mail --->
						<CFMAIL 
							FROM = "#LCase(mailFrom)#"
							TO = "#LCase(mailTo)#"
							SUBJECT = "#mailSubject#"
							TYPE = "HTML"
							QUERY = "qryCMFCUSTOMER">
								<CFIF ArrayLen(attachedFile)>
									<!--- Start - Loop - Attachment File --->
									<CFLOOP index="ctr2" from="1" to="#ArrayLen(attachedFile)#">
										<CFMAILPARAM file="#attachedFile[ctr2]#">
									</CFLOOP>
									<!--- End - Loop - Attachment File   --->
								</CFIF>
								Hi #contactName#, <BR/><BR/>
								#mailHeader# <BR/><BR/>
								#mailMessage#
								<TABLE>
								<TR>
								<TD><B>Platform:</B></TD>
								<TD>#platform#</TD>
								</TR>
								<TR>
								<TD><B>Component:</B></TD>
								<TD>#qryECINPRF.COMPONENT#</TD>
								</TR>
								<TR>
								<TD><B>Component Version:</B></TD>
								<TD>#qryECINPRF.VERSION#</TD>
								</TR>
								<TR>
								<BR/><BR/>
								<TD valign="top" align="left"><B>Problem Resolved/New Feature:</B></TD>
								<TD valign="top" align="left">#qryECINPRF.PROBRESNEWFEAT#</TD>
								</TR>
								<TR>
								<TD valign="top" align="left"><B>Table Modfication/New Table:</B></TD>
								<TD valign="top" align="left">#qryECINPRF.TABLEMODNEW#</TD>
								</TR>
								<TR>
								<TD valign="top" align="left"><B>Instruction to Administrator:</B></TD>
								<TD valign="top" align="left">#qryECINPRF.INSTRUCTION#</TD>
								</TR>
								<TR>
								<BR/><BR/>
								<TD valign="top" align="left"><B>Filename(s):</B></TD>
								<TD valign="top" align="left">#qryECINPRF.FILENAME#</TD>
								</TR>
								</TABLE>
								<BR/><BR/>						
								#mailFooter# 
								<BR/><BR/>								
								Thanks,<BR/>
								#testerName#
						</CFMAIL>
						<!--- End - Mail   --->
						<CFSET messageListEmailed = messageListEmailed & "<LI>#qryCMFCUSTOMER.CUSTOMERCODE#</LI>">
						<CFCATCH TYPE="ANY">
							<CFSET messageCatch = messageCatch & "<LI>#qryCMFCUSTOMER.CUSTOMERCODE# - #CFCATCH.MESSAGE# - #CFCATCH.DETAILS#</LI>">
						</CFCATCH>
					</CFTRY>
					<CFIF qryECINFORMSATTACH.RecordCount AND #ArrayLen(attachedFile)#>
						<!--- Start - Loop - Rename Back the File Attached --->
						<CFSET ctr3 = 1>
						<CFLOOP QUERY = "qryECINFORMSATTACH">
							<CFSET filename  = qryECINFORMSATTACH.ATTACHFILECODE>
							<CFSET extension = listLast(qryECINFORMSATTACH.DESCRIPTION,".")>
							<CFSET attachedFile[ctr3] = renameFile("#attachedFile[ctr3]#","#client.attachment_path##filename#.#extension#")>
							<CFSET ctr3 = ctr3 + 1>
						</CFLOOP>
						<!--- End - Loop - Rename Back the File Attached   --->
					</CFIF>
				<CFELSE>
					<CFSET messageListNoEmail = messageListNoEmail & "<LI>#qryCMFCUSTOMER.CUSTOMERCODE#</LI>">
				</CFIF> <!--- End - If - Email Exist   --->
			</CFLOOP> <!--- End - Loop - Customer   --->
			<CFSET sMessPostApproval = "#getMessage(messageListEmailed, messageListNoEmail, messageCatch)#">
			<CFOUTPUT>#getMessage(messageListEmailed, messageListNoEmail, messageCatch)#</CFOUTPUT>
		<CFELSE>
			<CFSET sMessPostApproval = "No Mail Template">
			<CFABORT>
		</CFIF>	<!--- End - If - Template Exist   --->
	</CFIF>	<!--- End - If - Active Customer Exist   --->	
</CFIF> <!--- End - IF - PRF Exist   --->

<!--- Start - Functions --->
<!--- Start - Function - Get Message --->
<CFFUNCTION NAME = "getMessage">
	<CFARGUMENT NAME = "emailed">
	<CFARGUMENT NAME = "noEmail">
	<CFARGUMENT NAME = "catched">
	<CFSET message = "">
	<CFIF emailed NEQ "">
		<CFSET message = message & "<UL>Mailed Client(s):" & " #emailed#</UL>">
	</CFIF>
	<CFIF noEmail NEQ "">
		<CFSET message = message & "<UL>Client(s) with no email: " & "#noEmail#</UL>">
	</CFIF>
	<CFIF catched NEQ "">
		<CFSET message = message & "<UL>Error Sending Email: " & "#catched#</UL>">
	</CFIF>
	<CFRETURN message>
</CFFUNCTION>
<!--- End - Function - Get Message   --->
<!--- Start - Function - Get Customer Email --->
<CFFUNCTION NAME = "getEmail">
	<CFARGUMENT NAME="queryCustomer">
	<CFSET mailTo = "">
	<CFIF #queryCustomer.EMAIL1#     NEQ ""><CFSET mailTo = #queryCustomer.EMAIL1#>
	<CFELSEIF #queryCustomer.EMAIL2# NEQ ""><CFSET mailTo = #queryCustomer.EMAIL2#>
	<CFELSEIF #queryCustomer.EMAIL3# NEQ ""><CFSET mailTo = #queryCustomer.EMAIL3#>
	</CFIF><CFRETURN mailTo>
</CFFUNCTION>
<!--- End - Function - Get Customer Email  --->
<!--- Start - Function - Get Customer Name --->
<CFFUNCTION NAME = "getContactName">
	<CFARGUMENT NAME="queryCustomer">
	<CFSET contactName = "">
	<CFIF #queryCustomer.CONTACT1#     NEQ ""><CFSET contactName = #queryCustomer.CONTACT1#>
	<CFELSEIF #queryCustomer.CONTACT2# NEQ ""><CFSET contactName = #queryCustomer.CONTACT2#>
	<CFELSEIF #queryCustomer.CONTACT3# NEQ ""><CFSET contactName = #queryCustomer.CONTACT3#>
	</CFIF><CFRETURN contactName>
</CFFUNCTION>
<!--- End - Function - Get Customer Name  --->
<!--- Start - Function - Get Codes with Specified Platform --->
<CFFUNCTION NAME = "getCodes">
	<CFARGUMENT NAME="platform">
	<CFSET codes = ''>
	<CFQUERY NAME="qryGetPlatforms" DATASOURCE="#client.company_dsn#">
		Select CUSTPLATFORMCODE, platforms from CLKCUSTPLATFORM
	</CFQUERY>
	<CFLOOP QUERY = "qryGetPlatforms">
		<CFQUERY NAME="qryGetPlatformsCode" DATASOURCE="#client.company_dsn#">	
			SELECT * FROM dbo.Split('#qryGetPlatforms.PLATFORMS#')
		</CFQUERY>
		<CFLOOP QUERY = "qryGetPlatformsCode">
			<CFIF trim(qryGetPlatformsCode.ITEMS[qryGetPlatformsCode.currentRow]) EQ platform>
				<CFSET codes = codes & "'" & #qryGetPlatforms.CUSTPLATFORMCODE[qryGetPlatforms.currentRow]# & "',">
			</CFIF>
		</CFLOOP>
	</CFLOOP>
	<CFSET codes = rereplace(#codes#, '(.*),', '\1') /> 
	<CFRETURN codes>
</CFFUNCTION>
<!--- End - Function - Get Codes with Specified Platform   --->
<!--- Start - Function - Rename File Attached --->
<CFFUNCTION NAME="renameFile">
	<CFARGUMENT NAME="oldName">
	<CFARGUMENT NAME="newName">
	<CFFILE ACTION = "rename" source="#ExpandPath(oldName)#" destination="#ExpandPath(newName)#" attributes="normal">
	<CFRETURN newName>
</CFFUNCTION>
<!--- End - Function - Rename File Attached   --->
<!--- End - Functions --->